<?php
/**
 * 前台登录 退出操作
 *
 *
 *
 *
 * @网店运维提供技术支持 授权请购买shopnc授权
 * @license    http://www.shopwwi.com
 * @link       交流群号：111731672 欢迎加入SHOP WWI.COM
 */



defined('InShopNC') or exit('Access Invalid!');

class loginControl extends BaseLoginControl {

    public function __construct(){
        parent::__construct();
    }

    //当前修改为手机登录
    public function indexOp(){
        header("Content-Type: text/html; charset=UTF-8");
        Language::read("home_login_index,home_login_register");
        $lang   = Language::getLangContent();
        $model_member   = Model('member');
        //检查登录状态
        $model_member->checkloginMember();
        /*if ($_GET['inajax'] == 1 && C('captcha_status_login') == '1'){
            $script = "document.getElementById('codeimage').src='index.php?act=seccode&op=makecode&nchash=".getNchash()."&t=' + Math.random();";
        }*/
        $result = chksubmit(true,C('captcha_status_login'),'num');

        if ($result !== false){
            if ($result === -11){
                showDialog($lang['login_index_login_illegal'],'','error',$script);
            }elseif ($result === -12){
                //showDialog($lang['login_index_wrong_checkcode'],'','error',$script);
            }
            if (process::islock('login')) {
                showDialog($lang['nc_common_op_repeat'],SHOP_SITE_URL,'','error',$script);
            }
            $obj_validate = new Validate();
            $user_name = $_POST['user_name'];
            $password = $_POST['password'];
            $obj_validate->validateparam = array(
                array("input"=>$user_name,     "require"=>"true", "message"=>$lang['login_index_username_isnull']),
                array("input"=>$password,      "require"=>"true", "message"=>$lang['login_index_password_isnull']),
            );
            $error = $obj_validate->validate();
            if ($error != ''){
                showDialog($error,SHOP_SITE_URL,'error',$script);
            }
           //查找用户
		    $condition = array();
            $condition['member_name'] = $user_name;
            //$condition['member_passwd'] = md5($password);
            $member_info = $model_member->getMemberInfo($condition);
            if(empty($member_info) && preg_match('/^0?(13|15|17|18|14)[0-9]{9}$/i', $user_name)) {//根据会员名没找到时查手机号
                $condition = array();
                $condition['member_mobile'] = $user_name;
                //$condition['member_passwd'] = md5($password);
                $member_info = $model_member->getMemberInfo($condition);
            }

            if(empty($member_info) && (strpos($user_name, '@') > 0)) {//按邮箱和密码查询会员
                $condition = array();
                $condition['member_email'] = $user_name;
                //$condition['member_passwd'] = md5($password);
                $member_info = $model_member->getMemberInfo($condition);
            }
            //用户登录检测
            if(is_array($member_info) && !empty($member_info) && $member_info['member_passwd']==md5($password)) {
                //用户验证通过
                if(!$member_info['member_state']){
                    showDialog($lang['login_index_account_stop'],'','error',$script);
                }
                if(C('ucenter_status')) {
                    $member_id=$member_info['member_id'];
                    //此处通过newuc model推送同步登录信息到其他端
                    $newuc=Model('newuc');
                    $data['uid']=$member_id;

                    $newuc->synlogin($data);//同步登录

                    if(intval($member_id) == 0) {
                        if (cookie('tm_login') >= 6){
                            showDialog($lang['nc_common_op_repeat']);
                        }
                        showDialog($lang['login_index_login_again']);
                    }
                }
            }else{
                //用户或密码错误时取ucenter
                if(C('ucenter_status')) {
                    //先判断是否存在用户
                    $newuc=Model('newuc');
                    $data['user_name']=$user_name;
                    $data['password']=$password;
                    $count=$newuc->get_count($data);
                    if($count==0){
                        echo "<script>alert('用户名/密码错误或者您的账号已被停用，请您尝试重新输入或者联系客服人员');history.back(-1);</script>";exit;
                    }
                    //UC用户验证通过 当前根据用户名删除
                    //查询本地用户 根据username更新uid等信息 存在则更新，不存在则写入
                    //var_dump($data);exit;
                    $count=$newuc->get_local_user_count($data);
                    //本地存在多个重复账号则删除 以UC账号为准 且用户名、邮箱、手机号唯一
                    //查uc用户数据
                    $uc_user_info=$newuc->get_uc_user_info($data);
                    //echo $count;exit;
                    $local_data=array();
                    $local_data['member_id']=$uc_user_info['uid'];
                    $local_data['member_name']=$uc_user_info['username'];
                    $local_data['member_passwd']=$uc_user_info['password'];
                    $local_data['member_email']=$uc_user_info['email'];
                    $local_data['member_mobile']=$uc_user_info['mobile'];
                    $local_data['member_type']=$uc_user_info['usertype'];
                    if($count==1){
                        //更新
                        $newuc->update_local_user($local_data,$data);
                        $member_info = $local_data;
                    }elseif($count>1){
                        //删除重复数据并重新写入
                        $newuc->delete_local_user($data);
                        $newuc->insert_local_user($local_data);
                    }elseif($count==0){
                        //写入
                        $newuc->insert_local_user($local_data);
                    }
                }
            }

            // 自动登录
            //unset($member_info);
            $member_info['auto_login'] = $_POST['auto_login'];
            $condition = array();
            $condition['member_mobile'] = $user_name;
            //$condition['member_passwd'] = md5($password);
           // $model_member   = Model('member');
           // $member_info = $model_member->getMemberInfo($condition);
            $model_member->createSession($member_info);
            //跳转到首页
            echo "<script>window.location.href='/';</script>";exit;  //UC同步暂时需要这样跳转，不可修改
        }else{
            //登录表单页面
            $_pic = @unserialize(C('login_pic'));
            if ($_pic[0] != ''){
                Tpl::output('lpic',UPLOAD_SITE_URL.'/'.ATTACH_LOGIN.'/'.$_pic[array_rand($_pic)]);
            }else{
                Tpl::output('lpic',UPLOAD_SITE_URL.'/'.ATTACH_LOGIN.'/'.rand(1,4).'.jpg');
            }

            if(empty($_GET['ref_url'])) {
                $ref_url = getReferer();
                if (!preg_match('/act=login&op=logout/', $ref_url)) {
                 $_GET['ref_url'] = $ref_url;
                }
            }
            Tpl::output('html_title',C('site_name').' - '.$lang['login_index_login']);
            if ($_GET['inajax'] == 1){
                Tpl::showpage('login_inajax','null_layout');
            }else{
                Tpl::showpage('login');
            }
        }
    }

    /**
     * 退出操作
     *
     * @param int $id 记录ID
     * @return array $rs_row 返回数组形式的查询结果
     */
    public function logoutOp(){
        Language::read("home_login_index");
        $lang   = Language::getLangContent();
        //设置同步登出参数
        $data['uid']=$_SESSION['member_id'];
        // 清理COOKIE
        setNcCookie('msgnewnum'.$_SESSION['member_id'],'',-3600);
        setNcCookie('auto_login', '', -3600);
        setNcCookie('cart_goods_num','',-3600);
        session_unset();
        session_destroy();
	  /**
		* 同步登录通知
		*/
        /**
         * Ucenter处理
         */
		if(C('ucenter_status')) {

            //此处改为同步退出
            $newuc=Model('newuc');
            $newuc->synlogout($data);
			/*$model_ucenter = Model('ucenter');
			$out_str = $model_ucenter->userLogout();
			$lang['login_logout_success'] = $lang['login_logout_success'].$out_str;	*/
            $lang['login_logout_success'] = $lang['login_logout_success'];
			if(empty($_GET['ref_url'])){
				$ref_url = getReferer();
			}else {
				$ref_url = $_GET['ref_url'];
			}
			showMessage($lang['login_logout_success'],'index.php?act=login&ref_url='.urlencode($ref_url));			
		}else{
			redirect('index.php');
		}
	}

    /**
     * 会员注册页面
     *
     * @param
     * @return
     */
    public function registerOp() {
        Language::read("home_login_register");
        $lang   = Language::getLangContent();
        $model_member   = Model('member');
        $model_member->checkloginMember();
        Tpl::output('html_title',C('site_name').' - '.$lang['login_register_join_us']);
        if(!empty($_GET['ref'])){
            setNcCookie('ref_member',$_GET['ref'],3600*24);//COOKIE
        }
        Tpl::showpage('register');
    }
    /*
    //当前修改为仅手机注册 改写 lee
    public function usersaveOp() {
        header("Content-Type: text/html; charset=UTF-8");
        //var_dump($_POST);exit;
        //相关检测
        if($_POST['register_phone']==''||$_POST['password']==''){
            echo "<script>alert('请您填写完整后尝试重新提交');history.back(-1);</script>";exit;
        }
        //手机格式验证
        if ( isset($_POST["register_phone"]) ){
            $pattern="/^((13[0-9])|(15[^4,\\D])|(17[0,6-8])|(18[0,5-9]))\\d{8}$/i";
            if ( !preg_match($pattern,$_POST["register_phone"]) )
            {
                echo "<script>alert('手机格式不正确');history.back(-1);</script>";exit;
            }
        }
        //先本地检测手机是否已被注册 如果本地没有，则UC检查，都没有，则可以注册
        $mobile=addslashes($_POST['register_phone']);
        //echo $mobile;exit;
        $newuc=Model('newuc');
        $count=$newuc->get_local_mobile_count($mobile);
        //echo $count;exit;
        if($count>0){
            //echo "<script>alert('此手机已经被注册，如果是您的账号，请您登录，或者更换别的手机继续注册，谢谢');history.back(-1);</script>";exit;
        }
        //连接到UC端检测
        $count=$newuc->get_uc_mobile_count($mobile);

        if($count>0){
            //echo "<script>alert('此手机已经被注册(本网站或关联网站)，请您尝试登录或使用别的手机进行注册，如有不明之处请联系客服人员');history.back(-1);</script>";exit;
            $remote_user_info = $newuc->get_uc_user_info(array('user_name'=>$mobile));
            $uid = $remote_user_info['uid'];
        }else {
            //写入UC 确保uid唯一
            $data['username'] = addslashes($_POST['member_name']);
            $data['password'] = addslashes($_POST['password']);
            $data['mobile'] = $mobile;
            $uid = $newuc->uc_mobile_reg($data);  //UID

            if ($uid <= 0) {
                echo "<script>alert('同步注册失败，请您重新尝试');history.back(-1);</script>";
                exit;
            }
        }
        //写入本地数据库
        $count=$newuc->get_local_mobile_count($mobile);
        if($count>0){ //删除
            if(!$newuc->local_mobile_delete($mobile)){
                echo "<script>alert('删除本地手机用户失败，请联系系统管理员');history.back(-1);</script>";exit;
            }
        }else{ //写入
            //写入UC 确保uid唯一
            $data=array();
            $data['member_id']=$uid;
            $data['member_name']=addslashes($_POST['member_name']);
            $data['member_passwd']=addslashes($_POST['password']);
            $data['member_mobile']=$mobile;
            if(!empty($remote_user_info))$data['member_type'] = $remote_user_info['usertype'];
            if(!empty( $remote_user_info['mobile'])||!empty($mobile))$data['member_mobile_bind'] = 1;
            //var_dump($data);exit;
            $member_id=$newuc->local_mobile_reg($data);  //UID
            //echo $member_id;exit;
            if($member_id<=0){
                echo "<script>alert('本地注册失败，请您重新尝试');history.back(-1);</script>";exit;
            }
        }
        //生成session或cookie，跳转到首页
        //查找用户
        $condition = array();
        $condition['member_mobile']=$mobile;
        $model_member   = Model('member');
        $member_info = $model_member->getMemberInfo($condition);
        $model_member->createSession($member_info);
        //同步登录
        //echo $member_id;exit;
        $data=array();
        $data['uid']=$member_id;
        $newuc->synlogin($data);//同步登录
        echo "<script>window.location.href='/';</script>";exit;  //UC同步暂时需要这样跳转，不可修改
    }*/

    public function usersaveOp() {
        //重复注册验证

        if (process::islock('reg')){
            showDialog(Language::get('nc_common_op_repeat'));
        }
        Language::read("home_login_register");
        $lang   = Language::getLangContent();
        $model_member   = Model('member');
        $model_member->checkloginMember();
        $result = chksubmit(true,C('captcha_status_register'),'num');
        if ($result){
            if ($result === -11){
                showDialog($lang['invalid_request'],'','error');
            }elseif ($result === -12){
                showDialog($lang['login_usersave_wrong_code'],'','error');
            }
        } else {
            showDialog($lang['invalid_request'],'','error');
        }
        if(C('assign_user_name')){
            $number = $model_member->getRegisterNum();
            $NumberLogic = Logic("number");
            $user_id = substr(date('Ym'),1,5).sprintf("%06s",$number+1);
            $user_code = $NumberLogic->encodeNum($user_id);
            $member_name = "JYC".substr($user_code,1);
            $member_name = $model_member->getCheckName($number,$member_name);
            $_POST['user_name'] = $member_name;
        }

        $member = $model_member->getMemberInfo(array('member_name' => $member_name));//检查重名

        if (!empty($member)) {
            showDialog('用户名已被注册', 'index.php?act=login&op=register');
        }

        $email = trim($_POST['email']);
        $member = $model_member->getMemberInfo(array('member_email' => $email));//检查重名
        if (!empty($member)) {
            showDialog('该邮箱已被注册', 'index.php?act=login&op=register');
        }

        if (C('ucenter_status')) {
            /* $model_ucenter = Model('ucenter');
             $remote_member_info = $model_ucenter->getUserInfo(trim($mobile), 4); */
            $newuc=Model('newuc');
            $remote_member_info=$newuc->get_uc_user_info(array('user_name'=>trim($_POST['email'])));
        }

        if (!empty($remote_member_info)) {
            //UC用户直接写入数据表
            $member = array();
            $member['member_id'] = $remote_member_info['uid'];
            $member['member_name'] = $remote_member_info['username'];
            $member['member_passwd'] = $remote_member_info['password'];
            $member['member_mobile'] = $remote_member_info['mobile'];
            $member['member_email'] = $remote_member_info['email'];
            $member['member_nickname'] = $remote_member_info['nickname'];
            $member['member_truename'] = $remote_member_info['truename'];
            $member['member_mobile_bind'] = 1;
            $member['plain_passwd'] = 1;
            $member['member_type'] = $remote_member_info['usertype'];
            $result = $model_member->addMember($member);
            if ($result) {
                $member_name = $remote_member_info['username'];
                $member = $model_member->getMemberInfo(array('member_name' => $member_name));
                $model_member->createSession($member, true);//自动登录
                process::addprocess('reg');

                $data = array();
                $data['member_email'] = $_POST['email'];
                $data['member_email_bind'] = 0;
                $update = $model_member->editMember(array('member_id'=>$_SESSION['member_id']),$data);
                if (!$update) {
                    showDialog('系统发生错误，如有疑问请与管理员联系');
                }

                $seed = random(6);
                $data = array();
                $data['auth_code'] = $seed;
                $data['send_acode_time'] = TIMESTAMP;
                $update = $model_member->editMemberCommon($data,array('member_id'=>$_SESSION['member_id']));
                if (!$update) {
                    showDialog('系统发生错误，如有疑问请与管理员联系');
                }
                $uid = base64_encode(encrypt($_SESSION['member_id'].' '.$_POST["email"]));
                $verify_url = LOGIN_SITE_URL.'/index.php?act=login&op=bind_email&uid='.$uid.'&hash='.md5($seed);

                $model_tpl = Model('mail_templates');
                $tpl_info = $model_tpl->getTplInfo(array('code'=>'bind_email'));
                $param = array();
                $param['site_name']	= C('site_name');
                $param['user_name'] = $_SESSION['member_name'];
                $param['verify_url'] = $verify_url;
                $subject	= ncReplaceText($tpl_info['title'],$param);
                $message	= ncReplaceText($tpl_info['content'],$param);

                $email	= new Email();
                $email->send_sys_email($_POST["email"],$subject,$message);

                $_POST['ref_url']   = (strstr($_POST['ref_url'],'logout')=== false && !empty($_POST['ref_url']) ? $_POST['ref_url'] : urlMember('member_information', 'member'));
                if ($_GET['inajax'] == 1){
                    showDialog('验证邮件已经发送至您的邮箱，请于24小时内登录邮箱并完成验证！',$_POST['ref_url'] == '' ? 'reload' : $_POST['ref_url'],'js');
                } else {
                    //redirect($_POST['ref_url']);
                    showMessage('验证邮件已经发送至您的邮箱，请于24小时内登录邮箱并完成验证！',$_POST['ref_url']);
                }
            }
        } else {
            /**
             * Ucenter处理
             */
            if (C('ucenter_status')) {
                Language::read("home_login_register");
                $lang = Language::getLangContent();
                $data = array();
                $passwd = md5(trim($_POST['password']));
                $mobile = null;
                $data['username']=$member_name;
                $data['truename'] = '';
                $data['password']=$passwd;
                $data['mobile']=$mobile;
                $data['email'] = $email;
                $data['usertype'] = 2;
                $data['regdate'] = time();
                //var_dump($data);exit;
                $newuc=Model('newuc');
                $uid=$newuc->uc_mail_reg($data);  //UID
                /*  $model_ucenter = Model('ucenter');
                  $uid = $model_ucenter->addUser(array('username' => $member_name, 'password' => $passwd, 'mobile' => trim($mobile), 'email' => '', 'member_type' => 2));*/

                //if($uid<1) showMessage($lang['login_usersave_regist_fail'],'','html','error');
            }
            if($uid){
                $remote_member_info=$newuc->get_uc_user_info(array('user_name'=>trim($_POST['email'])));
            }else{
                showMessage('网络忙,请稍后再试');
            }
            $member = array();
            $member['member_id'] = $remote_member_info['uid'];
            $member['member_number'] = $number;
            $member['member_name'] = $member_name;
            $member['member_passwd'] = $passwd;
            $member['member_mobile'] = $mobile;
            $member['member_email'] = $email;
            $member['member_nickname'] = $remote_member_info['nickname'];
            $member['member_truename'] = trim($_POST['truename']);
            $member['member_type'] = $remote_member_info['usertype'];
            $ref_member = cookie('ref_member');
            if(!empty($ref_member)){
                $mobile['member_invite'] = $ref_member;
            }
            $result = $model_member->addMember($member);
            if ($result) {
                $member = $model_member->getMemberInfo(array('member_name' => $member_name));
                $model_member->createSession($member, true);//自动登录
                process::addprocess('reg');

                $data = array();
                $data['member_email'] = $_POST['email'];
                $data['member_email_bind'] = 0;
                $update = $model_member->editMember(array('member_id'=>$_SESSION['member_id']),$data);
                if (!$update) {
                    showDialog('系统发生错误，如有疑问请与管理员联系');
                }

                $seed = random(6);
                $data = array();
                $data['auth_code'] = $seed;
                $data['send_acode_time'] = TIMESTAMP;
                $update = $model_member->editMemberCommon($data,array('member_id'=>$_SESSION['member_id']));
                if (!$update) {
                    showDialog('系统发生错误，如有疑问请与管理员联系');
                }
                $uid = base64_encode(encrypt($_SESSION['member_id'].' '.$_POST["email"]));
                $verify_url = LOGIN_SITE_URL.'/index.php?act=login&op=bind_email&uid='.$uid.'&hash='.md5($seed);

                $model_tpl = Model('mail_templates');
                $tpl_info = $model_tpl->getTplInfo(array('code'=>'bind_email'));
                $param = array();
                $param['site_name']	= C('site_name');
                $param['user_name'] = $_SESSION['member_name'];
                $param['verify_url'] = $verify_url;
                $subject	= ncReplaceText($tpl_info['title'],$param);
                $message	= ncReplaceText($tpl_info['content'],$param);

                $email	= new Email();
                $email->send_sys_email($_POST["email"],$subject,$message);

                $_POST['ref_url']   = (strstr($_POST['ref_url'],'logout')=== false && !empty($_POST['ref_url']) ? $_POST['ref_url'] : urlMember('member_information', 'member'));
                if ($_GET['inajax'] == 1){
                    showDialog('验证邮件已经发送至您的邮箱，请于24小时内登录邮箱并完成验证！',$_POST['ref_url'] == '' ? 'reload' : $_POST['ref_url'],'js');
                } else {
                    //redirect($_POST['ref_url']);
                    showMessage('验证邮件已经发送至您的邮箱，请于24小时内登录邮箱并完成验证！',$_POST['ref_url']);
                }

            } else {
                showMessage('注册失败', 'index.php?act=login&op=register');
            }
        }


    }
    /**
     * 会员名称检测
     *
     * @param
     * @return
     */
    public function check_memberOp() {
		if(C('ucenter_status')) {
			/**
		 	* 实例化Ucenter模型
		 	*/
			$model_ucenter = Model('ucenter');
			$result = $model_ucenter->checkUserExit(trim($_GET['user_name']));
			if($result == 1) {
				echo 'true';
			} else {
				echo 'false';
			}
		} else {
            /**
            * 实例化模型
            */
            $model_member   = Model('member');

            $check_member_name  = $model_member->getMemberInfo(array('member_name'=>$_GET['user_name']));
            if(is_array($check_member_name) && count($check_member_name)>0) {
                echo 'false';
            } else {
                echo 'true';
            }
    }}

    /**
     * 电子邮箱检测
     *
     * @param
     * @return
     */
    public function check_emailOp() {
		if(C('ucenter_status')) {
			/**
		 	* 实例化Ucenter模型

			$model_ucenter = Model('ucenter');
			$result = $model_ucenter->checkEmailExit(trim($_GET['email']));*/
            $newuc=Model('newuc');
            $result = $newuc->get_uc_user_info(array('user_name'=>trim($_GET['email'])));
			if($result) {
				echo 'false';
			} else {
				echo 'true';
			}

		} else{
        $model_member = Model('member');
        $check_member_email = $model_member->getMemberInfo(array('member_email'=>$_GET['email']));
        if(is_array($check_member_email) && count($check_member_email)>0) {
            echo 'false';
        } else {
            echo 'true';
        }
    }}

    /**
     * 忘记密码页面
     */
    public function forget_passwordOp(){
        /**
         * 读取语言包
         */
        Language::read('home_login_register');
        $_pic = @unserialize(C('login_pic'));
        if ($_pic[0] != ''){
            Tpl::output('lpic',UPLOAD_SITE_URL_HTTPS.'/'.ATTACH_LOGIN.'/'.$_pic[array_rand($_pic)]);
        }else{
            Tpl::output('lpic',UPLOAD_SITE_URL_HTTPS.'/'.ATTACH_LOGIN.'/'.rand(1,4).'.jpg');
        }
        Tpl::output('html_title',C('site_name').' - '.Language::get('login_index_find_password'));
        Tpl::showpage('find_password');
    }

    /**
     * 找回密码的发邮件处理
     */
    public function find_passwordOp(){
        Language::read('home_login_register');
        $lang   = Language::getLangContent();

      //  $result = chksubmit(true,true,'num');
        if ($result !== false){
            if ($result === -11){
                showDialog('非法提交','','error');
            }elseif ($result === -12){
                showDialog('验证码错误','','error');
            }
        }
      /*
        if(empty($_POST['username'])){
            showDialog($lang['login_password_input_username'],'','error');
        }
     */
        if (process::islock('forget')) {
            showDialog($lang['nc_common_op_repeat'],'','error');
        }

        $member_model   = Model('member');
       // $member = $member_model->getMemberInfo(array('member_name'=>$_POST['username']));
        $member = $member_model->getMemberInfo(array('member_email'=>$_POST['email']));

        if(empty($member) or !is_array($member)){
            process::addprocess('forget');
            showDialog($lang['login_password_username_not_exists'],'','error');
        }
       /*
        if(empty($_POST['email'])){
            showDialog($lang['login_password_input_email'],'','error');
        }

        if(strtoupper($_POST['email'])!=strtoupper($member['member_email'])){
            process::addprocess('forget');
            showDialog($lang['login_password_email_not_exists'],'','error');
        }
       */
        process::clear('forget');
        //产生密码
        $new_password   = random(10);
        if(!($member_model->editMember(array('member_id'=>$member['member_id']),array('member_passwd'=>md5($new_password))))){
            showDialog($lang['login_password_email_fail'],'','error');
        }else{
			if(C('ucenter_status')) {
				/**
				* Ucenter处理
				*/
				/*$model_ucenter = Model('ucenter');
				$model_ucenter->userEdit(array('username'=>$member['member_name'],'password'=>trim($new_password)),1);*/
                $newuc=Model('newuc');
                $newuc->update_uc_passwd(trim($new_password),$member['member_id']);
			}}

        $model_tpl = Model('mail_templates');
        $tpl_info = $model_tpl->getTplInfo(array('code'=>'reset_pwd'));
        $param = array();
        $param['site_name'] = C('site_name');
        $param['user_name'] = $_POST['username'];
        $param['new_password'] = $new_password;
        $param['site_url'] = SHOP_SITE_URL;
        $subject    = ncReplaceText($tpl_info['title'],$param);
        $message    = ncReplaceText($tpl_info['content'],$param);

        $email	= new Email();
        $email->send_sys_email($_POST["email"],$subject,$message); //."  MD5: ".md5($new_password)
        //登出操作
        setNcCookie('msgnewnum'.$_SESSION['member_id'],'',-3600);
        setNcCookie('auto_login', '', -3600);
        setNcCookie('cart_goods_num','',-3600);
        session_unset();
        session_destroy();
        if ($_GET['inajax'] == 1) {
            showDialog('新密码已经发送至您的邮箱，请尽快登录并更改密码！', 'index.php?act=login&op=index','html','error');
        }else{
            showMessage('新密码已经发送至您的邮箱，请尽快登录并更改密码！','index.php?act=login&op=index','html','error');
        }
    }

    /**
     * 邮箱绑定验证
     */
    public function bind_emailOp() {
       $model_member = Model('member');
       $uid = @base64_decode($_GET['uid']);
       $uid = decrypt($uid,'');
       list($member_id,$member_email) = explode(' ', $uid);

       if (!is_numeric($member_id)) {
           showMessage('验证失败',SHOP_SITE_URL,'html','error');
       }

       $member_info = $model_member->getMemberInfo(array('member_id'=>$member_id),'member_email');
       if ($member_info['member_email'] != $member_email) {
           showMessage('验证失败',SHOP_SITE_URL,'html','error');
       }

       $member_common_info = $model_member->getMemberCommonInfo(array('member_id'=>$member_id));
       if (empty($member_common_info) || !is_array($member_common_info)) {
           showMessage('验证失败',SHOP_SITE_URL,'html','error');
       }
       if (md5($member_common_info['auth_code']) != $_GET['hash'] || TIMESTAMP - $member_common_info['send_acode_time'] > 24*3600) {
           showMessage('验证失败',SHOP_SITE_URL,'html','error');
       }

       $update = $model_member->editMember(array('member_id'=>$member_id),array('member_email_bind'=>1));
       if (!$update) {
           showMessage('系统发生错误，如有疑问请与管理员联系',SHOP_SITE_URL,'html','error');
       }

       $data = array();
       $data['auth_code'] = '';
       $data['send_acode_time'] = 0;
       $update = $model_member->editMemberCommon($data,array('member_id'=>$_SESSION['member_id']));
       if (!$update) {
           showDialog('系统发生错误，如有疑问请与管理员联系');
       }
       showMessage('邮箱设置成功','index.php?act=member_security&op=index');

    }
}
